package model;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class ClassTest {


	@Test
	public void classWithMethod(){
		SysClass c = new SysClass("C");
		SysMethod m = new SysMethod(false,"m","C","default");
		c.add(m);
		assertTrue(c.contains(m));
	}

	@Test
	public void ClassWithMethod2(){
		SysClass c = new SysClass("C");
		SysMethod m = new SysMethod(false,"m","D","default");
		c.add(m);
		assertTrue(c.contains(m));
	}

	@Test
	public void classWithoutMethod(){
		SysClass c = new SysClass("C");
		SysMethod m = new SysMethod(false,"m", "C", "default");
		assertFalse(c.contains(m));
	}

	@Test
	public void twoInstancesRepresentingSameMethod(){
		SysMethod m1 = new SysMethod(false,"m1","r", "default");
		SysMethod m2 = new SysMethod(false,"m1","r", "default");
		SysClass c = new SysClass("c");
		c.add(m1);
		assertTrue(c.contains(m2));
	}

	@Test
	public void twoSimilarMethodsInInstance(){
		SysClass r = new SysClass("r");
		SysClass c = new SysClass("c");
		SysMethod m1 = new SysMethod(false,"m1","r", "default");
		m1.addParameter(r.getFullyQualifiedName());
		SysMethod m2 = new SysMethod(false,"m1","r", "default");
		c.add(m1);
		assertFalse(c.contains(m2));
	}

	@Test
	public void classWithField(){
		SysClass c = new SysClass("C");
		SysField attribute = new SysField(true, c.getFullyQualifiedName(), "Atribute", "default");
		c.add(attribute);
		assertTrue(c.contains(attribute));
	}

	@Test
	public void classWithoutField(){
		SysClass c = new SysClass("C");
		SysField a = new SysField(false, c.getFullyQualifiedName(),"attribute", "default");
		assertFalse(c.contains(a));		
	}

	@Test
	public void twoInstancesRepresentingSameField(){
		SysClass c = new SysClass("C");
		SysField a = new SysField(true, c.getFullyQualifiedName(),"attribute", "default");
		SysField b = new SysField(true, c.getFullyQualifiedName(),"attribute", "default");
		c.add(a);
		assertTrue(c.contains(b));
	}

	@Test
	public void twoInstancesRepresentingSameFieldUpperCase(){
		SysClass c = new SysClass("C");
		SysField a = new SysField(true, c.getFullyQualifiedName(),"attribute", "default");
		SysField b = new SysField(true, c.getFullyQualifiedName(),"ATTRIBUTE", "default");
		c.add(a);
		assertFalse(c.contains(b));
	}

	@Test
	public void twoInstancesRepresentingSimilarField(){
		SysClass c = new SysClass("C");
		SysField a = new SysField(true, c.getFullyQualifiedName(),"attribute", "default");
		SysField b = new SysField(true, c.getFullyQualifiedName(),"ATTRIBUT", "default");
		c.add(a);
		assertFalse(c.contains(b));
	}

	@Test
	public void methodBelongsToClass() {
		SysClass c = new SysClass("C");
		SysMethod m = new SysMethod(false, "m", "Integer", "private");
		c.add(m);
		assertTrue(m.getOwner().equals(c));
	}

	@Test
	public void sameFullyQualifiedName(){
		SysClass c = new SysClass("SysClass");
		SysClass d = new SysClass("SysClass");
		assertTrue(c.equalsIgnoreFullyQualifiedName(d));
	}

	@Test
	public void differentFullyQualifiedName(){
		SysPackage p = new SysPackage("SysGraph4AJ.model");
		SysClass c = new SysClass("SysClass");
		SysClass d = new SysClass("SysClass");
		//System.out.println(c.getFullyQualifiedName());

		p.add(c);   

		//System.out.println(c.getFullyQualifiedName());
		//System.out.println(d.getFullyQualifiedName());
		assertFalse(c.equals(d));
	}

	@Test
	public void samePackageAndFullyQualifiedName(){
		SysPackage p1 = new SysPackage("SysGraph4AJ.model");
		SysPackage p2 = new SysPackage("SysGraph4AJ.model");
		SysClass c = new SysClass("SysClass");
		SysClass d = new SysClass("SysClass");
		p1.add(c);
		p2.add(d);
		assertTrue(c.equals(d));
	}

	@Test
	public void classWithSuperClass(){
		SysClass a = new SysClass("Class");
		SysClass sc = new SysClass("SuperClass");
		a.setSuperClass(sc);
		assertTrue(a.getSuperClass().equals(new SysClass("SuperClass")));
	}







}
